
var mongoose = require('mongoose'); 
var db = mongoose.createConnection('localhost','O2O');
db.on('error',console.error.bind(console,'连接错误:'));
db.once('open',function(){
	var _con = function (info) {
		this._id = "U_"+Math.random().toString(16).substr(2)+(+new Date).toString(16);
		this.info = {};
		this.info.name = info.name;
		this.info.password = info.pwd;
		this.classify = null;
		this.create_time = +new Date;
	}

	var Schema = mongoose.Schema;
	var userSchema = new Schema({
		_id:String,
		info:{
			name:String,
			password:String
		},
		classify:String,
		create_time:Number
	});
	var UserCon = db.model('User_test', userSchema);

	var user = new UserCon(new _con({
		name:"gaubee",
		pwd:"12456"
	}))

	console.log(user);

	// user.save(function () {
	// 	console.log("saved");
	// 	UserCon.find(function () {
	// 		console.log(arguments);
	// 		UserCon.findById(user._id,function () {
	// 			console.log(arguments);
	// 			db.close()
				
	// 		})
	// 	});
	// });


	// UserCon.find(function () {
	// 	console.log(arguments);
		db.close()
	// });
});